<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Returns an individual field of an error report</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.pg-query.html">« pg_query</a></li>
      <li style="float: right;"><a href="function.pg-result-error.html">pg_result_error »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.pgsql.html">PostgreSQL 函数</a></li>
    <li>Returns an individual field of an error report</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.pg-result-error-field" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">pg_result_error_field</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">pg_result_error_field</span> &mdash; <span class="dc-title">Returns an individual field of an error report</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.pg-result-error-field-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>pg_result_error_field</strong></span>(<span class="methodparam"><span class="type"><a href="class.pgsql-result.html" class="type PgSql\Result">PgSql\Result</a></span> <code class="parameter">$result</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$field_code</code></span>): <span class="type"><span class="type">string</span>|<span class="type"><span class="type false">false</span></span>|<span class="type">null</span></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>pg_result_error_field()</strong></span> returns one of the detailed error message
   fields associated with <code class="parameter">result</code> instance. It is only available
   against a PostgreSQL 7.4 or above server.  The error field is specified by
   the <code class="parameter">field_code</code>.
  </p>
  <p class="para">
   Because <span class="function"><a href="function.pg-query.html" class="function">pg_query()</a></span> and <span class="function"><a href="function.pg-query-params.html" class="function">pg_query_params()</a></span> return <strong><code>false</code></strong> if the query fails,
   you must use <span class="function"><a href="function.pg-send-query.html" class="function">pg_send_query()</a></span> and
   <span class="function"><a href="function.pg-get-result.html" class="function">pg_get_result()</a></span> to get the result handle.
  </p>
  <p class="para">
   If you need to get additional error information from failed <span class="function"><a href="function.pg-query.html" class="function">pg_query()</a></span> queries,  
   use <span class="function"><a href="function.pg-set-error-verbosity.html" class="function">pg_set_error_verbosity()</a></span> and <span class="function"><a href="function.pg-last-error.html" class="function">pg_last_error()</a></span>
   and then parse the result.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.pg-result-error-field-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">result</code></dt>

     <dd>

      <p class="para">An <span class="classname"><a href="class.pgsql-result.html" class="classname">PgSql\Result</a></span> instance, returned by <span class="function"><a href="function.pg-query.html" class="function">pg_query()</a></span>,
<span class="function"><a href="function.pg-query-params.html" class="function">pg_query_params()</a></span> or <span class="function"><a href="function.pg-execute.html" class="function">pg_execute()</a></span>(among others).</p>
     </dd>

    
    
     <dt>
<code class="parameter">field_code</code></dt>

     <dd>

        <p class="para">
         Possible <code class="parameter">field_code</code> values are: <strong><code>PGSQL_DIAG_SEVERITY</code></strong>,
         <strong><code>PGSQL_DIAG_SQLSTATE</code></strong>, <strong><code>PGSQL_DIAG_MESSAGE_PRIMARY</code></strong>,
         <strong><code>PGSQL_DIAG_MESSAGE_DETAIL</code></strong>,
         <strong><code>PGSQL_DIAG_MESSAGE_HINT</code></strong>, <strong><code>PGSQL_DIAG_STATEMENT_POSITION</code></strong>,
         <strong><code>PGSQL_DIAG_INTERNAL_POSITION</code></strong> (PostgreSQL 8.0+ only),
         <strong><code>PGSQL_DIAG_INTERNAL_QUERY</code></strong> (PostgreSQL 8.0+ only),
         <strong><code>PGSQL_DIAG_CONTEXT</code></strong>, <strong><code>PGSQL_DIAG_SOURCE_FILE</code></strong>,
         <strong><code>PGSQL_DIAG_SOURCE_LINE</code></strong> or
         <strong><code>PGSQL_DIAG_SOURCE_FUNCTION</code></strong>.
        </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.pg-result-error-field-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">A <span class="type">string</span> containing the contents of the error field, <strong><code>null</code></strong> if the field does not exist or <strong><code>false</code></strong>
  on failure.</p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.pg-result-error-field-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
 <td>8.1.0</td>
 <td>
  现在 <code class="parameter">result</code> 参数接受 <span class="classname"><a href="class.pgsql-result.html" class="classname">PgSql\Result</a></span>
  实例，之前接受 <a href="language.types.resource.html" class="link">资源(resource)</a>。
 </td>
</tr>

    </tbody>
   
  </table>

 </div>

 
 <div class="refsect1 examples" id="refsect1-function.pg-result-error-field-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-1928">
    <p><strong>示例 #1 <span class="function"><strong>pg_result_error_field()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />&nbsp;&nbsp;$dbconn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"dbname=publisher"</span><span style="color: #007700">)&nbsp;or&nbsp;die(</span><span style="color: #DD0000">"Could&nbsp;not&nbsp;connect"</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;if&nbsp;(!</span><span style="color: #0000BB">pg_connection_busy</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbconn</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">pg_send_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbconn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"select&nbsp;*&nbsp;from&nbsp;doesnotexist;"</span><span style="color: #007700">);<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$res1&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_get_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbconn</span><span style="color: #007700">);<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">pg_result_error_field</span><span style="color: #007700">(</span><span style="color: #0000BB">$res1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">PGSQL_DIAG_SQLSTATE</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.pg-result-error-field-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.pg-result-error.html" class="function" rel="rdfs-seeAlso">pg_result_error()</a> - 获得查询结果的错误信息</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>